package com.cnap.model.file;

import cn.hutool.core.util.IdUtil;
import com.cnap.db.entity.FileInfoPO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 * 文件初始化请求
 *
 * @author xc
 **/
@ApiModel
public class FileInitReq {
    // md5
    @ApiModelProperty(value = "哈希值")
    private String md5;
    // name
    @ApiModelProperty(value = "文件名称")
    @NotBlank(message = "文件名称不能为空")
    @Pattern(regexp = "(.+)\\.(zip)$", message = "文件名非法，请使用zip压缩包")
    private String name;
    // 总大小
    @ApiModelProperty(value = "文件大小")
    @DecimalMax(value = "9223372036854775807", message = "文件大小应小于9223372036854775807")
    private long totalSize;
    // 分片数量
    @ApiModelProperty(value = "分片数量")
    @DecimalMin(value = "1", message = "分片大小应大于0")
    private int patchNums;

    /**
     * 获取
     *
     * @return MD5
     */
    public String getMd5() {
        return md5;
    }

    /**
     * set
     *
     * @param md5 md5
     */
    public void setMd5(String md5) {
        this.md5 = md5;
    }

    /**
     * get
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * set
     *
     * @param name name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * get
     *
     * @return totalSize
     */
    public long getTotalSize() {
        return totalSize;
    }

    /**
     * set
     *
     * @param totalSize totalSize
     */
    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    /**
     * num
     *
     * @return num
     */
    public int getPatchNums() {
        return patchNums;
    }

    /**
     * num
     *
     * @param patchNums num
     */
    public void setPatchNums(int patchNums) {
        this.patchNums = patchNums;
    }

    @Override
    public String toString() {
        return "md5='" + md5 + '\'' +
                ", name='" + name + '\'' +
                ", totalSize=" + totalSize +
                ", patchNums=" + patchNums;
    }

    /**
     * 转换成po
     *
     * @return po
     */
    public FileInfoPO toPO() {
        FileInfoPO fileInfoPO = new FileInfoPO();
        fileInfoPO.setId(IdUtil.simpleUUID());
        fileInfoPO.setFileName(this.name);
        // FIXME 不写md5值
        fileInfoPO.setMd5("");
        fileInfoPO.setTotalSize(this.totalSize);
        fileInfoPO.setPatchNums(this.patchNums);

        return fileInfoPO;
    }
}
